<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>美兰数据文化馆与图书馆</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/formSelects-v4.css" media="all">
</head>
<style>
    /* 底部固定区域 */
    .layui-layout-admin .layui-footer {
        padding: 10px 0;
        text-align: center;
    }

    .layui-layout-admin .layui-footer {
        background-color: #fff;
    }

    .layui-form-label {
        width: 90px;
    }

    .layui-input-block {
        margin-left: 120px;
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header" style="font-size: 25px;color:#fff; background: -webkit-linear-gradient(left,#4282c8, #234b75, transparent, transparent);
   background: -o-linear-gradient(left,#4282c8, #234b75,transparent, transparent);
   background: -moz-linear-gradient(left,#4282c8, #234b75, transparent, transparent);
   background: -ms-linear-gradient(left,#4282c8, #234b75, transparent, transparent);border-bottom: none">
            有毒有害、易制毒危险化学品领用申请单
        </div>
        <div class="layui-card-body">
            <div class="layui-form">
                <div class="layui-row">
                    <fieldset class="layui-elem-field">
                        <legend>审批内容</legend>
                        <div class="layui-field-box">
                            <div class="layui-form-item">
                                <div class="layui-col-xs12">
                                    <div class="layui-col-xs6">
                                        <div class="layui-col-xs11">
                                            <div class="layui-inline"
                                                 style="margin-bottom: 0px;margin-right: 0px;width: 100%">
                                                <label class="layui-form-label">主题</label>
                                                <div class="layui-input-block">
                                                    <input type="text"
                                                           class="layui-input"
                                                           style="border-left:0px;border-right: 0px;border-top: 0px;"
                                                           name="name" id="name" lay-verify="name">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-xs1">
                                            <div class="layui-form-mid layui-word-aux"
                                                 style="color: red !important;padding: 10px !important;">*
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-xs11">
                                    <div class="layui-col-xs3">
                                        <div class="layui-block"
                                             style="margin-bottom: 0px;margin-right: 0px;width: 83%">
                                            <label class="layui-form-label">批号</label>
                                            <div class="layui-input-block">
                                                <div class="layui-input-inline" style="width: 78px;margin:0px;">
                                                    <input type="text" autocomplete="off" class="layui-input"
                                                           value="460108GB" name="display" disabled
                                                           style="border-left:0px;border-right: 0px;border-top: 0px;">
                                                </div>
                                                <div class="layui-input-block" style="margin-left:78px;width: 100%">
                                                    <input type="text" autocomplete="off" class="layui-input"
                                                           placeholder="" id="batchNumber" name="batchNumber"
                                                           style="padding-left:0px;border-left:0px;border-right: 0px;border-top: 0px;background-color:#fff;color:#6f6868; "
                                                           disabled>
                                                </div>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-col-md12">
                                <div class="layui-row layui-col-space15">
                                    <div class="layui-col-sm6">
                                        <div class="layui-form">
                                            <div class="layui-card-header" style="padding: 0 10px;">明细
                                            </div>
                                            <div class="layui-tab-content" style="height: auto">
                                                <div class="layui-form-item" >
                                                    <div class="layui-col-xs11">
                                                        <label class="layui-form-label">订单号</label>
                                                        <div class="layui-input-block">
                                                            <select name="orderNumber" id="orderNumber" lay-filter="test">

                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <div class="layui-col-lg12">
                                                        <div class="layui-col-xs11">
                                                            <label class="layui-form-label">试剂名称</label>
                                                            <div class="layui-input-block">
                                                                <div class="layui-form">
                                                                    <select name="suppliesName" id="suppliesName"
                                                                            xm-select="suppliesName" xm-select-radio=""
                                                                            lay-verify="suppliesName"
                                                                            xm-select-search="">
                                                                    </select>
                                                                </div>

                                                            </div>
                                                        </div>
                                                        <div class="layui-col-xs1">
                                                            <div class="layui-form-mid layui-word-aux"
                                                                 style="color: red !important;padding: 10px !important;">
                                                                *
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <div class="layui-col-lg12">
                                                        <div class="layui-col-xs11">
                                                            <label class="layui-form-label">库存数量</label>
                                                            <div class="layui-input-block">
                                                                <input type="text"
                                                                       autocomplete="off"
                                                                       class="layui-input" disabled id="quantity">
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <div class="layui-col-lg12">
                                                        <div class="layui-col-xs11">
                                                            <label class="layui-form-label">领取数量</label>
                                                            <div class="layui-input-block">
                                                                <input type="text" name="inventory"
                                                                       autocomplete="off" placeholder="请输入领取数量"
                                                                       class="layui-input"
                                                                       id="inventory"
                                                                       oninput="value=value.replace(/[^\d]+/g,'')"
                                                                       maxlength="9" min="1">
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <div class="layui-col-lg12" style="text-align: center">
                                                        <button class="layui-btn layui-btn-xs layui-bg-blue"
                                                                id="addSupplies">新增清单
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-col-sm6">
                                        <div class="layui-card-header" style="padding: 0 10px;">领用清单
                                        </div>
                                        <div class="layui-tab-content" style="height: auto">
                                            <table class="layui-hide" id="collectRecordTable"
                                                   lay-filter="collectRecordTables"></table>
                                            <div id="laypage"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="layui-row">
                    <div class="layui-form-item">
                        <fieldset class="layui-elem-field">
                            <legend>流程处理</legend>
                            <div class="layui-field-box">
                                <div class="layui-form">
                                    <div class="layui-form-item">
                                        <div class="layui-col-xs12">
                                            <div class="layui-col-xs6">
                                                <div class="layui-inline"
                                                     style="margin-bottom: 0px;margin-right: 0px;width: 83%">
                                                    <label class="layui-form-label">紧急程度</label>
                                                    <div class="layui-input-block">
                                                        <input type="radio" name="urgent" value="紧急"
                                                               title="紧急">
                                                        <input type="radio" name="urgent" value="急"
                                                               title="急">
                                                        <input type="radio" name="urgent" value="一般"
                                                               title="一般" checked>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-col-xs12">
                                            <div class="layui-col-xs6">
                                                <div class="layui-col-xs11">
                                                    <div class="layui-inline"
                                                         style="margin-bottom: 0px;margin-right: 0px;width: 100%">
                                                        <label class="layui-form-label">申请科室:</label>
                                                        <div class="layui-input-block">
                                                            <select name="departmenttid" xm-select="departmenttid"
                                                                    xm-select-search=""
                                                                    xm-select-radio="" id="departmenttid"
                                                                    lay-verify="departmenttid">
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="layui-col-xs1">
                                                    <div class="layui-form-mid layui-word-aux"
                                                         style="color: red !important;padding: 10px !important;">*
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-col-xs12">
                                            <div class="layui-col-xs6">
                                                <div class="layui-col-xs11">
                                                    <div class="layui-inline"
                                                         style="margin-bottom: 0px;margin-right: 0px;width: 100%">
                                                        <label class="layui-form-label">审批人员:</label>
                                                        <div class="layui-input-block">
                                                            <select name="usertid" xm-select="usertid"
                                                                    xm-select-search=""
                                                                    xm-select-radio="" id="usertid"
                                                                    lay-verify="usertid">
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="layui-col-xs1">
                                                    <div class="layui-form-mid layui-word-aux"
                                                         style="color: red !important;padding: 10px !important;">*
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-col-xs12">
                                            <div class="layui-col-xs3">
                                                <div class="layui-inline"
                                                     style="margin-bottom: 0px;margin-right: 0px;width: 100%">
                                                    <label class="layui-form-label">申请人:</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" value="${user.name}"
                                                               class="layui-input" name="application"
                                                               style="border-left:0px;border-right: 0px;border-top: 0px;"
                                                               disabled>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <input type="hidden" name="type" value="2">
                                    <div class="layui-form-item">
                                        <div class="layui-col-xs12">
                                            <div class="layui-col-xs3">
                                                <div class="layui-inline"
                                                     style="margin-bottom: 0px;margin-right: 0px;width: 100%">
                                                    <label class="layui-form-label">申请时间:</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" id="datetime" name="datetime"
                                                               autocomplete="off"
                                                               class="layui-input"
                                                               readonly=""
                                                               style="border-left:0px;border-right: 0px;border-top: 0px;"
                                                               lay-verify="datetime">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-col-xs1">
                                                <div class="layui-form-mid layui-word-aux"
                                                     style="color: red !important;padding: 10px !important;">*
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-col-xs12">
                                            <div class="layui-col-xs6">
                                                <div class="layui-col-xs11">
                                                    <div class="layui-inline"
                                                         style="margin-bottom: 0px;margin-right: 0px;width: 100%">
                                                        <label class="layui-form-label">申请人意见:</label>
                                                        <div class="layui-input-block">
                                                            <textarea name="opinion" class="layui-textarea"
                                                                      id="opinion"></textarea>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-col-xs12">
                                            <div class="layui-col-xs6">
                                                <div class="layui-col-xs11">
                                                    <div class="layui-inline"
                                                         style="margin-bottom: 0px;margin-right: 0px;width: 100%">
                                                        <label class="layui-form-label">备注:</label>
                                                        <div class="layui-input-block">
                                                            <textarea name="remarks" class="layui-textarea"
                                                                      id="remarks"></textarea>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>
<%--                <div class="layui-row">--%>
<%--                    <input type="hidden" id="fileTid" name="fileTid">--%>
<%--                    <div class="layui-form-item">--%>
<%--                        <fieldset class="layui-elem-field">--%>
<%--                            <legend>附件</legend>--%>
<%--                            <div class="layui-field-box">--%>
<%--                                <ul class="layadmin-serach-list layui-text" id="filelist">--%>
<%--                                </ul>--%>
<%--                                <div class="layui-upload">--%>
<%--                                    <div class="layui-row layui-col-space15">--%>
<%--                                        <div class="layui-btn-container">--%>
<%--                                            <button type="button" class="layui-btn layui-btn-normal"--%>
<%--                                                    id="testList">选择文件--%>
<%--                                            </button>--%>
<%--                                            <button type="button" class="layui-btn layui-hide"--%>
<%--                                                    id="testListAction"--%>
<%--                                            >开始上传--%>
<%--                                            </button>--%>
<%--                                        </div>--%>
<%--                                    </div>--%>
<%--                                    <div class="layui-upload-list">--%>
<%--                                        <table class="layui-table">--%>
<%--                                            <thead>--%>
<%--                                            <tr>--%>
<%--                                                <th>文件名</th>--%>
<%--                                                <th>大小</th>--%>
<%--                                                <th>状态</th>--%>
<%--                                                <th>操作</th>--%>
<%--                                            </tr>--%>
<%--                                            </thead>--%>
<%--                                            <tbody id="demoList"></tbody>--%>
<%--                                        </table>--%>
<%--                                    </div>--%>
<%--                                </div>--%>
<%--                            </div>--%>
<%--                        </fieldset>--%>
<%--                    </div>--%>
<%--                </div>--%>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-footer" style="left: 0;padding: 0px;">
                        <button class="layui-btn" lay-submit lay-filter="ddfdfs" id="pushButton">提交申请</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="curnum" value="1">
<script type="text/html" id="table-inventory">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="<%=request.getContextPath()%>/huazhi/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'laydate', 'formSelects','laypage'], function () {
        var $ = layui.$
            , table = layui.table
            , layer = layui.layer,
            form = layui.form,
            laydate = layui.laydate
            , formSelects = layui.formSelects,
            laypage=layui.laypage;


        $.ajax({
            type: "post",
            url: "<%=request.getContextPath()%>/rest/supplies/getNumberNo",
            dataType: "json",
            async: false,
            success: function (msg) {
                var select = document.getElementById("orderNumber");
                select.options.add(new Option(msg,msg));
                form.render('select');

                var limitcount = 10;
                table.render({
                    elem: '#collectRecordTable'
                    , url: "<%=request.getContextPath()%>/rest/process/getListCollectRecord"
                    , title: "领用清单表",
                    height: 'full-450'
                    , page: false
                    // , toolbar: '#suppliesCollectOperation'
                    , limit: limitcount
                    , text: {
                        none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                    },
                    where: {"random": msg},
                    skin: 'line',
                    defaultToolbar: ['filter', 'print']
                    // ,skin: 'line' //表格风格
                    , cols: [[
                        // {type: 'checkbox'}
                        {title: 'ID', width: 70, sort: true, fixed: 'left', type: 'numbers'}
                        , {field: 'suppliesname', title: '试剂名称', sort: true}
                        , {field: 'quantity', title: '领用数量', sort: true}
                        , {title: '操作', toolbar: '#table-inventory', fixed: "right", align: "center", width: 200}
                    ]],
                    done: function (res, curr, count) {
                        var curnum = $("#curnum").val();
                        $('.layui-table-fixed-r').removeClass('layui-hide');//列固定右侧
                        laypage.render({
                            elem: 'laypage'
                            , first: '首页'
                            , last: '尾页'
                            , groups: 5
                            , count: count
                            , curr: curnum
                            , limit: limitcount
                            , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                            , limits: [10, 15, 20]
                            , jump: function (obj, first) {
                                if (!first) {
                                    curnum = obj.curr;
                                    $("#curnum").val(curnum)
                                    limitcount = obj.limit;
                                    table.reload('collectRecordTable', { //表格的id
                                        where: {
                                            page: curnum,
                                            limit: limitcount
                                        }
                                    })
                                }
                            }
                        })
                    }
                });

            }
        });


        $.ajax({
            type: "post",
            url: "<%=request.getContextPath()%>/rest/process/getNumberNos",
            dataType: "json",
            async: false,
            success: function (msg) {
                var select = document.getElementById("orderNumber");
                $.each(msg,function(i,n) {
                    select.options.add(new Option(n,n));
                })
                form.render('select');
            }
        });

        //.....................................




        $.ajax({
            type: "post",
            url: "<%=request.getContextPath()%>/rest/process/getChemicalList",
            dataType: "json",
            async: false,
            success: function (msg) {
                formSelects.data('suppliesName', 'local', {
                    arr: msg
                });
            }
        })

        formSelects.on('suppliesName', function(id, vals, val, isAdd, isDisabled){
            if (val.value == "") {
                $("#quantity").val("");
            } else {
                if(isAdd){
                    $.ajax({
                        type: "post",
                        url: "<%=request.getContextPath()%>/rest/process/getChemicalByTid",
                        dataType: "json",
                        data: "tid=" + val.value,
                        async: false,
                        success: function (msg) {
                            var quantity = msg.quantity;
                            $("#quantity").val(parseInt(quantity));
                        }
                    })
                }else{
                    $("#quantity").val("");
                }
            }

            //如果return false, 那么将取消本次操作
        });


        //清单
        form.on('select(test)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            $("#curnum").val("1");
            table.reload('collectRecordTable', { //表格的id
                where: {
                    random: data.value,
                    page: 1,
                    limit: 10,
                },
                text: {
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                }
            })


        });

        //监听工具条
        table.on('tool(collectRecordTables)', function (obj) {  //表格的lay-filter="userlists"
            var data = obj.data; //获得当前行所有数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (obj.event === 'del') {
                del(data, obj)
            }
        });

        function del(data, obj) {
            layer.confirm('确定删除此数据', {icon: 3, title: '提示信息', shade: 0.6}, function (index) {
                layer.close(index);
                layer.msg('删除中，请稍候', {icon: 16, time: false, shade: 0.6});
                setTimeout(function () {
                    //向服务端发送删除指令
                    $.ajax({
                        type: "post",
                        url: "<%=request.getContextPath()%>/rest/process/deleteCollectRecord",
                        data: "tid=" + data.tid,
                        dataType: "json",
                        async: false,
                        success: function (msg) {
                            layer.close(index);
                            if (msg.data == true) {
                                layer.msg('删除成功');
                                var yyy=formSelects.value('suppliesName', 'valStr');

                                if(yyy==""){

                                }else {
                                    $("#quantity").val( msg.count);
                                }
                                obj.del();
                            } else {
                                layer.msg(msg.errorMsg);
                            }
                        }
                    })
                }, 2000);
            });
        }


        $("#addSupplies").click(function () {
            var suppliesTid = formSelects.value('suppliesName', 'valStr');
            // var suppliesTid = $("#suppliesName").val()
            if (suppliesTid == "") {
                // $(".xm-hide-input").addClass("layui-form-danger");
                // $(".xm-hide-input").focus();
                layer.msg('请选择名称', {icon: 5, shift: 6});
                return false
            } else {
                var inventory = $("#inventory").val()
                if (inventory == "") {
                    var numbersId = document.getElementById("inventory");
                    numbersId.setAttribute("class", "layui-input layui-form-danger");
                    numbersId.focus();
                    layer.msg('请输入领取数量', {icon: 5, shift: 6});
                } else {
                    var quantity = $("#quantity").val();
                    var random1 = $("#orderNumber").val();

                    if (quantity == 0) {
                        layer.msg('库存数量已用完', {icon: 5, shift: 6});
                    } else {
                        if (parseInt(inventory) == 0) {
                            var numbersId = document.getElementById("inventory");
                            numbersId.setAttribute("class", "layui-input layui-form-danger");
                            numbersId.focus();
                            layer.msg('请输入领取数量', {icon: 5, shift: 6});
                        } else {
                            if (parseInt(quantity) >= parseInt(inventory)) {
                                $.ajax({
                                    type: "post",
                                    url: "<%=request.getContextPath()%>/rest/process/addChemicalCollect",
                                    dataType: "json",
                                    async: false,
                                    data: "suppliesTid=" + suppliesTid + "&inventory=" + inventory + "&random=" + random1,
                                    success: function (msg) {
                                        if (msg = true) {
                                            layer.msg('添加成功');
                                            $("#quantity").val("");
                                            $("#inventory").val("")
                                            // $("#suppliesName").val("");
                                            // form.render('select');
                                            formSelects.value('suppliesName', []);
                                            $("#curnum").val("1");
                                            table.reload('collectRecordTable', { //表格的id
                                                where: {
                                                    random: random1,
                                                    page: 1,
                                                    limit: 10,
                                                },
                                                text: {
                                                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                                                }
                                            })
                                        } else {
                                            layer.msg(msg.errorMsg);
                                        }
                                    }
                                })
                            } else {
                                layer.msg('领取数量大于库存数量,请重新输入领取数量', {icon: 5, shift: 6});
                            }
                        }
                    }
                }
            }

        });


        //.............


        var batchNumber = generateClientID()
        $("#batchNumber").val(batchNumber)
        //.................

        //日期
        laydate.render({
            elem: '#datetime',
            btns: ['now', 'confirm'],
            theme: 'molv',
            type: 'date',
            calendar: true
            , format: 'yyyy年MM月dd日'
        });

        $.ajax({
            type: "post",
            url: "<%=request.getContextPath()%>/rest/system/getDepartmentList",
            dataType: "json",
            async: false,
            success: function (msg) {
                formSelects.data('departmenttid', 'local', {
                    arr: msg
                });
            }
        })

        formSelects.on('departmenttid', function (id, vals, val, isAdd, isDisabled) {
            // alert("当前选择了: " + JSON.stringify(vals));
            var arr = JSON.stringify(vals)
            var jsonObj = JSON.parse(arr);//转换为json对象
            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/rest/system/getListUserByDepartmenttidPosition",
                dataType: "json",
                async: false,
                data: "departmenttid=" + val.value,
                success: function (obj) {
                    formSelects.data('usertid', 'local', {
                        arr: obj
                    });
                }
            })

            if (jsonObj.length == 0) {
                formSelects.value('usertid', []);
                formSelects.data('usertid', 'local', {
                    arr: []
                });
            }
        }, true);


        //自定义验证规则
        form.verify({
            name: function (value, item) {
                if (value == "") {
                    return '请输入主题';
                }
            },
            departmenttid: function (value, item) {
                if (value == "") {
                    return '请选择申请科室';
                }
            },
            usertid: function (value, item) {
                if (value == "") {
                    return '请选择申请科室主任';
                }
            },
            datetime: function (value, item) {
                if (value == "") {
                    return '请选择申请时间';
                }
            }
        });

        //第一种方法添加用户
        form.on('submit(ddfdfs)', function (data) {
            var field = data.field//当前容器的全部表单字段，名值对形式：{name: value}
            var name = field.name;
            if (name == "") {
                var nameId = document.getElementById("name");
                nameId.setAttribute("class", "layui-input layui-form-danger");
                nameId.focus();
                layer.msg('请输入主题', {icon: 5, shift: 6});
                return false;
            }

            var orderNumber = field.orderNumber;
            var flag = true;

            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/rest/process/detailedListByOrderNumber",
                data: "orderNumber=" + orderNumber,
                dataType: "json",
                async: false,
                success: function (obj) {
                    flag = obj;
                }
            })
            if (!flag) {
                layer.msg('请添加领用清单', {icon: 5, shift: 6});
                return false;
            }

            var confirm=true;
            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/rest/process/detailedByOrderNumber",
                data: "orderNumber=" + orderNumber,
                dataType: "json",
                async: false,
                success: function (obj) {
                    confirm = obj;
                }
            })
            if (!confirm) {
                layer.msg('该订单号已经申请', {icon: 5, shift: 6});
                return false;
            }


            var index = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.6});
            $("#pushButton").addClass("layui-btn layui-btn-disabled").prop("disabled", true);
            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/rest/process/addStart",
                data: field,
                dataType: "json",
                async: false,
                success: function (obj) {


                    setTimeout(function () {
                        layer.close(index);
                        if (obj = true) {
                            var batchNumber = generateClientID()
                            $("#batchNumber").val(batchNumber)
                            layer.msg('提交成功');
                            $("#pushButton").removeClass("layui-btn-disabled").prop("disabled", false);
                            $("#name").val("");
                            var batchNumbers = generateClientID()
                            $("#batchNumber").val(batchNumber)
                            table.reload('chemicalApplicationTable', { //表格的id
                                where: {
                                    key: "",
                                    batchNumber: batchNumbers
                                },
                                text: {
                                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                                }
                            })

                            formSelects.value('departmenttid', []);
                            formSelects.data('departmenttid', 'local', {
                                arr: []
                            });

                            $.ajax({
                                type: "post",
                                url: "<%=request.getContextPath()%>/rest/system/getDepartmentList",
                                dataType: "json",
                                async: false,
                                success: function (msg) {
                                    formSelects.data('departmenttid', 'local', {
                                        arr: msg
                                    });
                                }
                            })

                            formSelects.value('usertid', []);
                            formSelects.data('usertid', 'local', {
                                arr: []
                            });

                            $("#datetime").val("");
                            $("#opinion").val("");
                            $("#remarks").val("");
                            $("#orderNumber").val("");
                            $("#quantity").val("");
                            $("#inventory").val("");
                            formSelects.value('suppliesName', []);
                            table.reload('collectRecordTable', { //表格的id
                                where: {
                                    random: "",
                                    page: 1,
                                    limit: 10,
                                },
                                text: {
                                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                                }
                            })


                        } else {
                            layer.msg(obj.errorMsg);
                        }
                    }, 2000);
                    setTimeout(function () {
                        var indexs = parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                        parent.layer.close(indexs);//关闭弹出层
//                        window.parent.location.reload();//刷新父页面
                    }, 4000);
                }
            })
            return false;
        });

    });


    var sessions = [];

    function generateClientID() {
        var clientID = '';
        var possible = "0123456789";
        var numPossible = possible.length;
        do {
            for (var i = 0; i < 8; i++) {
                clientID += possible.charAt((Math.random() * numPossible) | 0);
            }
        } while (sessions['clientID'] != null);
        return clientID;
    }
</script>
</body>
</html>